package cn.gzsxt.music.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gzsxt.music.query.ModularQueryObject;
import cn.gzsxt.music.service.ModularService;
import cn.gzsxt.music.vo.MsgObj;

@Controller
@Scope("request")
@RequestMapping("/modular")
public class ModularController {
	
	//引入service层
	@Autowired
	private ModularService service;
	
	@RequestMapping("modularPage")
	public String modularPage() {
		
		return "modularPage";
	}
	/**
	 * 	前台使用easui的datagrid接受列表数据,是一个json,map集合可以转换成json
	 * 	格式如下
	 *  {"total":2,"rows":[
			{"modular_id":"1","modular_name":"系统管理模块"},
			{"modular_id":"1","modular_name":"质押管理模块"},
		]}
	 * @return
	 */
	@RequestMapping("modularList")
	@ResponseBody
	public Map<String, Object> modularList(ModularQueryObject qo) {
		System.out.println(qo);
		 Map<String, Object> result = service.selectModularDataByCondition(qo);
		return result;
	}
	
	@RequestMapping("saveOrUpdateModular")
	@ResponseBody
	public MsgObj saveOrUpdateModular(@RequestParam Map<String,Object> params) {
		int row = service.saveOrUpdateModular(params);
		
		MsgObj msgObj = new MsgObj(0, "操作失败");
		if(row==1) {
			msgObj = new MsgObj(1, "操作成功");
		}
		return msgObj;
	}
	
	
	@RequestMapping("deleteModularById")
	@ResponseBody
	public MsgObj deleteModularById(Long modular_id) {
		
		int row = service.deleteModularById(modular_id);
		
		MsgObj msgObj = new MsgObj(0, "删除失败");
		if(row==1) {
			msgObj = new MsgObj(1, "删除成功");
		}
		return msgObj;
	}
}
